package com.example.hello.controller;

import com.example.hello.pojo.Result;
import com.example.hello.pojo.userin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
//@Controller
//@ResponseBody
public class ResponseController {
    /*@RequestMapping("/hello1")
    public String hello1() {
        return "Hello1";
    }

    @RequestMapping("/getuser")
    public userin getUser() {
        userin user1 = new userin();
        user1.setId("user1");
        user1.setPwd("123456");
        return user1;
    }

    @RequestMapping("/listuser")
    public List<userin> listUser() {
        List<userin> userList = new ArrayList<>();
        userin user1 = new userin();
        user1.setId("user1");
        user1.setPwd("123456");
        userList.add(user1);
        userin user2 = new userin();
        user2.setId("user2");
        user2.setPwd("123456");
        userList.add(user2);
        return userList;
    }*/

    //改造为result返回结果统一格式
    @RequestMapping("/hello1")
    public Result hello1() {
        //return new Result(1, "success", "Hello1");//直接返回json格式
        return Result.success("Hello1");//调用内部静态方法
    }

    @RequestMapping("/getuser")
    public Result getUser() {
        userin user1 = new userin();
        user1.setId("user1");
        user1.setPwd("123456");
        return Result.success(user1);
    }

    @RequestMapping("/listuser")
    public Result listUser() {
        List<userin> userList = new ArrayList<>();
        userin user1 = new userin();
        user1.setId("user1");
        user1.setPwd("123456");
        userList.add(user1);
        userin user2 = new userin();
        user2.setId("user2");
        user2.setPwd("123456");
        userList.add(user2);
        return Result.success(userList);
    }
}
